package demo;

import application.Infix2Postfix;
import zhengqc.list.ArrayList;

import java.util.Arrays;

public class DemoInfix2Postfix {
    public static void test(String infix, Infix2Postfix infix2Postfix) {
        System.out.println("infix: " + infix);
        infix2Postfix.setInfix(infix);
        if (!infix2Postfix.isValid()) {
            System.out.println("Not Valid!!");
            return;
        }
        ArrayList<Character> postfix = infix2Postfix.transform();
        System.out.println("postfix: " + Arrays.toString(postfix.toArray()));
        System.out.println("result: " + infix2Postfix.calculate());
    }
    public static void main(String[] args) {
        Infix2Postfix infix2Postfix = new Infix2Postfix();
        test("1+2-3*((4+5-6*(7+8))/9)", infix2Postfix);
        System.out.println();
        test("1+2-3+(5-6*7+8)/2)", infix2Postfix);
    }
}
